package com.fastloan.utils;

import org.apache.commons.lang.math.RandomUtils;
import org.apache.poi.ss.formula.functions.T;

import java.util.*;

import static java.util.stream.Collectors.toList;

/**
 * list随机取值
 *
 * @author chenkai
 *         createTime 2017-11-2017/11/10 17:40
 */
public class RandomDataUtil {

    public static <T> Set<T> generateRandomDataNoRepeat(Set<T> tempSet, List<T> list, Integer generateNum) {
        int number = generateNum < list.size() ? generateNum : list.size();
        if (tempSet.size() < number) {
            tempSet.add(list.get(RandomUtils.nextInt(number)));
            generateRandomDataNoRepeat(tempSet, list, generateNum);
        }
        return tempSet;
    }

}

